class IUP_FLAT_FRAME
-- Creates a native container, which draws a frame with a title around its 
-- child. The decorations are manually drawn. The control inherits from 
-- IUP_BACKGROUND_BOX. Inherits all attributes and callbacks of the IUP_CANVAS, 
-- but redefines a few attributes.

inherit
	IUP_BACKGROUND_BOX
		rename
			background_box_empty as flat_frame_empty,
			background_box as flat_frame
		redefine
			flat_frame_empty,
			flat_frame,
			set_rgb_background_color,
			set_decoration
		end
	IUP_WIDGET_TITLE
	IUP_WIDGET_FLAT_TEXT

create {ANY}
	flat_frame_empty,
	flat_frame

feature {ANY}

	flat_frame_empty
		-- Create an empty flat frame.
		local
			a_flat_frame, p: POINTER
		do
			a_flat_frame := int_flat_frame (p)
			set_widget(a_flat_frame)
		end

	flat_frame (child: IUP_WIDGET)
		-- Create a flat frame with the child.
		--
		-- child: Identifier of an interface element which will receive the frame 
		-- around.	
		local
			a_flat_frame: POINTER
		do
			a_flat_frame := int_flat_frame (child.widget)
			set_widget(a_flat_frame)
		end

	-- Attributes

	set_decoration (state: BOOLEAN)
		-- Does nothing since the frame always have a decoration.
		do
		end

	set_rgb_background_color (red: INTEGER; green: INTEGER; blue: INTEGER)
		-- Background color of the child area. If not defined it will use the 
		-- background color of the native parent.
		do
			Precursor (red, green, blue)
		end

	disable_frame
		-- (non inheritable): Disables the frame line.
		do
			iup_open.set_attribute(Current, "FRAME", "NO")
		end

	set_frame_line
		-- (non inheritable): Enables the frame line.
		do
			iup_open.set_attribute(Current, "FRAME", "YES")
		end

	set_frame_cross_title
		-- (non inheritable): Enables the frame cross title.
		do
			iup_open.set_attribute(Current, "FRAME", "CROSSTITLE")
		end

	get_frame_value: STRING
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "FRAME")

			Result := str
		end

	set_rgb_frame_color (red: INTEGER; green: INTEGER; blue: INTEGER)
		-- (non inheritable): frame line color. Default: the global attribute 
		-- DLGFGCOLOR.	
		do
			iup_open.set_attribute(Current, "FRAMECOLOR", rgb_to_string(red, green, blue))
		end

	get_rgb_frame_color: TUPLE[INTEGER, INTEGER, INTEGER]
		do
			Result := iup_open.get_rgb(Current, "FRAMECOLOR")
		end

	set_frame_width (value: INTEGER)
		-- (non inheritable): frame line width. Default: 1.
		require
			value > 0
		do
			iup_open.set_attribute(Current, "FRAMEWIDTH", value.to_string)
		end

	get_frame_width: INTEGER
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "FRAMEWIDTH")

			Result := str.to_integer
		end

	set_frame_space (value: INTEGER)
		-- (non inheritable): spacing between frame line and child area. Used 
		-- only when FRAME=True. Default: 2.
		require
			value >= 0
		do
			iup_open.set_attribute(Current, "FRAMESPACE", value.to_string)
		end

	get_frame_space: INTEGER
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "FRAMESPACE")

			Result := str.to_integer
		end

	set_rgb_title_color (red: INTEGER; green: INTEGER; blue: INTEGER)
		-- (non inheritable): title text color. Default: the global attribute 
		-- DLGFGCOLOR.
		do
			iup_open.set_attribute(Current, "TITLECOLOR", rgb_to_string(red, green, blue))
		end

	get_rgb_title_color: TUPLE[INTEGER, INTEGER, INTEGER]
		do
			Result := iup_open.get_rgb(Current, "TITLECOLOR")
		end

	set_rgb_title_background_color (red: INTEGER; green: INTEGER; blue: INTEGER)
		-- (non inheritable): background color of the title area. Default: the 
		-- global attribute DLGBGCOLOR.
		do
			iup_open.set_attribute(Current, "TITLEBGCOLOR", rgb_to_string(red, green, blue))
		end

	get_rgb_title_background_color: TUPLE[INTEGER, INTEGER, INTEGER]
		do
			Result := iup_open.get_rgb(Current, "TITLEBGCOLOR")
		end

	set_title_line (state: BOOLEAN)
		-- (non inheritable): enables the title line. Horizontal line that 
		-- separates the title area from the child area. Default: True.
		do
			iup_open.set_attribute(Current, "TITLELINE", boolean_to_yesno(state))
		end

	has_title_line: BOOLEAN
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "TITLELINE")

			Result := yesno_to_boolean(str)
		end

	set_rgb_title_line_color (red: INTEGER; green: INTEGER; blue: INTEGER)
		-- (non inheritable): title line color. Default: the global attribute 
		-- DLGFGCOLOR.	
		do
			iup_open.set_attribute(Current, "TITLELINECOLOR", rgb_to_string(red, green, blue))
		end

	get_rgb_title_line_color: TUPLE[INTEGER, INTEGER, INTEGER]
		do
			Result := iup_open.get_rgb(Current, "TITLELINECOLOR")
		end

	set_title_line_width (value: INTEGER)
		-- (non inheritable): title line width. Default: 1.
		require
			value > 0
		do
			iup_open.set_attribute(Current, "TITLELINEWIDTH", value.to_string)
		end

	get_title_line_width: INTEGER
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "TITLELINEWIDTH")

			Result := str.to_integer
		end

	set_title_image (imagename: STRING)
		-- (non inheritable): image name to be used in title. Use
		-- set_attribute_handle to associate an image to a name. 
		-- See also IUP_IMAGE.
		do
			iup_open.set_attribute(Current, "TITLEIMAGE", imagename)
		end

	get_title_image: STRING
		do
			Result := iup_open.get_attribute(Current, "TITLEIMAGE")
		end

	set_title_image_inactive (imagename: STRING)
		-- (non inheritable): image used in title when inactive. If it is not 
		-- defined then the TITLEIMAGE is used and its colors will be replaced by 
		-- a modified version creating the disabled effect. 
		do
			iup_open.set_attribute(Current, "TITLEIMAGEINACTIVE", imagename)
		end

	get_title_image_inactive: STRING
		do
			Result := iup_open.get_attribute(Current, "TITLEIMAGEINACTIVE")
		end

	set_title_image_position (position: STRING)
		-- (non inheritable): position of the image relative to the text when 
		-- both are displayed. Can be: LEFT, RIGHT, TOP, BOTTOM. Default: LEFT.
		require
			is_valid_position(position)
		do
			iup_open.set_attribute(Current, "TITLEIMAGEPOSITION", position)
		end

	get_title_image_position: STRING
		do
			Result := iup_open.get_attribute(Current, "TITLEIMAGEPOSITION")
		end

	set_title_image_spacing (value: INTEGER)
		-- (non inheritable): spacing between the image and the text.
		-- Default:	"2".
		require
			value >= 0
		do
			iup_open.set_attribute(Current, "TITLEIMAGESPACING", value.to_string)
		end

	get_title_image_spacing: INTEGER
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "TITLEIMAGESPACING")

			Result := str.to_integer
		end

	set_title_alignment (value: STRING)
		-- (non inheritable): horizontal alignment. Possible values: "ALEFT", 
		-- "ACENTER" and "ARIGHT". Default: "ACENTER".
		require
			is_valid_horizontal_alignment(value)
		do
			iup_open.set_attribute(Current, "TITLEALIGNMENT", value)
		end

	get_title_alignment: STRING
		do
			Result := iup_open.get_attribute(Current, "TITLEALIGNMENT")
		end

	set_title_text_alignment (value: STRING)
		-- (non inheritable): horizontal text alignment for multiple lines. Can 
		-- be: ALEFT, ARIGHT or ACENTER. Default: ALEFT.
		require
			is_valid_horizontal_alignment(value)
		do
			iup_open.set_attribute(Current, "TITLETEXTALIGNMENT", value)
		end

	get_title_text_alignment: STRING
		do
			Result := iup_open.get_attribute(Current, "TITLETEXTALIGNMENT")
		end

	set_title_padding (horizontal, vertical: INTEGER)
		-- (non inheritable): title internal margin. Default value: "0x0".
				local
			str: STRING
		do
			create str.copy(horizontal.to_string)
	      str.append_string("x")
 	      str.append_string(vertical.to_string)
	
			iup_open.set_attribute(Current, "TITLEPADDING", str)
		end

	get_title_padding: TUPLE[INTEGER, INTEGER]
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "TITLEPADDING")

			Result := components_of (str, 'x')
		end

feature {}

	-- Internals
	
	int_flat_frame_empty (arguments: POINTER): POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupFlatFrame"
         }"
      end
	
   int_flat_frame (arguments: POINTER): POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupFlatFrame"
         }"
      end

	-- Validations

	is_valid_position (value: STRING): BOOLEAN
		do
			if value.is_equal("LEFT") or
				value.is_equal("RIGHT") or
				value.is_equal("TOP") or
				value.is_equal("BOTTON") then
				Result := True
			else
				Result := False
			end
		end

end

-- The MIT License (MIT)

-- Copyright (c) 2017, 2018, 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
